package org.example.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.example.constans.WxConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxMpConfig {

    @Bean
    public WxMpDefaultConfigImpl wxMpDefaultConfigImpl() {
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(WxConstants.APP_ID); // 设置微信公众号的appid
        config.setSecret(WxConstants.APP_SECRET); // 设置微信公众号的app corpSecret
        config.setToken(WxConstants.TOKEN); // 设置微信公众号的token
        config.setAesKey("qe7qkmbEzKrZ88rE8LQK32kiO1P5BZHhPeT9pB3MqNt"); // 设置微信公众号的EncodingAESKey
        return config;
    }
    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();// 实际项目中请注意要保持单例，不要在每次请求时构造实例，具体可以参考demo项目
        wxMpService.setWxMpConfigStorage(wxMpDefaultConfigImpl());
        return wxMpService;
    }
}
